package com.lancoo.znbkxx.teacher.aibkTestCoach.questionToMark.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.ItemMark
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.SubjectData

/**
 * Created by Dadong on 2020/9/27
 * Describe:
 */
class SubjectAdapter(private val context: Context, private val itemList: List<SubjectData>) : KBaseRecyclerAdapter() {

    private lateinit var tvSubject: TextView
    private lateinit var vSelect: View
    private var onItemClickListener: OnItemClickListener? = null

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(context).inflate(R.layout.item_comment_subject, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {
        tvSubject = holder.itemView.findViewById(R.id.tv_subject)
        vSelect = holder.itemView.findViewById(R.id.v_select)

        if (itemList[position].isShowMark) {
            vSelect.visibility = View.VISIBLE
        } else {
            vSelect.visibility = View.GONE
        }
        if (itemList[position].isSelect) {
            tvSubject.setTextColor(holder.itemView.resources.getColor(R.color.white))
            tvSubject.background = holder.itemView.resources.getDrawable(R.drawable.bg_comment_select)
        } else {
            tvSubject.setTextColor(holder.itemView.resources.getColor(R.color.c009CFF))
            tvSubject.background = holder.itemView.resources.getDrawable(R.drawable.bg_comment_unselect)
        }
        tvSubject.text = itemList[position].childIndex
        tvSubject.setOnClickListener {
            onItemClickListener!!.onItemClickPlay(position, vSelect)
        }
    }

    override fun getItemCount(): Int {
        return itemList.size
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    fun setOnItemClickListener(listener: OnItemClickListener?) {
        onItemClickListener = listener
    }

    interface OnItemClickListener {
        fun onItemClickPlay(position: Int, view: View?)
    }
}